package com.dissertation.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;

import java.time.LocalDateTime;

public abstract class MongodbBaseModel {

    @Id
    private String id;

    @NotEmpty
    private String uniqueName;

    @JsonIgnore
    private LocalDateTime createTime = LocalDateTime.now();

    @JsonIgnore
    private boolean deleted; // true表示已经删除

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted( boolean deleted ) {
        this.deleted = deleted;
    }

    public String getId() {
        return id;
    }

    public void setId( String id ) {
        this.id = id;
    }

    public String getUniqueName() {
        return uniqueName;
    }

    public void setUniqueName( String uniqueName ) {
        this.uniqueName = uniqueName;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    @Override
    public boolean equals( Object o ) {
        if ( this == o ) return true;
        if ( o == null || getClass() != o.getClass() ) return false;

        MongodbBaseModel that = (MongodbBaseModel) o;

        return id.equals( that.id );
    }

    @Override
    public int hashCode() {
        if ( id == null ) {
            return -1;
        }
        return id.hashCode();
    }



}
